define(["jqform","layuiall"], function (jqform,layui) {
    var form  = layui.form;
    var Controller = {

        index:function () {
            form.on('switch(status)', function(data){
                var status = 0;
                if(data.elem.checked){
                    status = 1
                }
                $.ajax({
                    type:'post',
                    data:{
                        id:data.value,
                        status:status
                    },
                    url:$(data.elem).attr("data-url"),
                    success:function (res) {
                        layer.msg(res.msg)
                    }
                })
            });
            form.on('switch(recommended)', function(data){
                var recommended = 0;
                if(data.elem.checked){
                    recommended = 1
                }
                $.ajax({
                    type:'post',
                    data:{
                        id:data.value,
                        recommended:recommended
                    },
                    url:$(data.elem).attr("data-url"),
                    success:function (res) {
                        layer.msg(res.msg)
                    }
                })
            });
            jqform.delete()
            //数据全部选中
            form.on('checkbox(select-all)', function(data){

                if(data.elem.checked==true){
                    $("input[name='idList[]']").prop('checked',true)
                }else {
                    $("input[name='idList[]']").prop('checked',false)
                }
                form.render('checkbox');
            });
        },
        addtag: function () {
            jqform.init()
        },
        edittag:function () {
            jqform.init()
        }
    }
    return Controller;
});